package com.ktwlsoft.archivemanage.controller.register;

import com.ktwlsoft.archivemanage.domain.business.businessService.register.RegisterService;
import com.ktwlsoft.archivemanage.domain.dao.entity.register.AccountRegister;
import com.ktwlsoft.archivemanage.payload.Result;
import com.ktwlsoft.archivemanage.payload.ResultType;
import com.ktwlsoft.archivemanage.service.security.UserAuthenticate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 注册相关
 *
 * @author Name on 2020/7/9 10:48
 * @version 1.0
 */
@Api(value = "注册相关", description = "注册相关")
@RestController
@RequestMapping("register")
public class RegisterController {

    /**注册*/
    private final RegisterService registerService;

    public RegisterController(RegisterService registerService) {
        this.registerService = registerService;
    }

    @ApiOperation(value = "注册审核列表")
    @ResponseBody
    @GetMapping("findPage")
    public ResponseEntity<?> findPage(@RequestParam(defaultValue = "1") int pn,
                                      @RequestParam(defaultValue = "30") int pageSize,
                                      @ApiParam(name = "keyWords", value = "关键字") @RequestParam(defaultValue = "", required = false) String keyWords,
                                      @ApiParam(name = "type", value = "类型:待审核(WAIT_FOR),已通过(ADOPT),已打回(REPULSE)") @RequestParam(defaultValue = "", required = false) String type) {
        return ResponseEntity.ok(registerService.findPage(pn,pageSize,keyWords,type));
    }

    @ApiOperation(value = "注册新增")
    @ResponseBody
    @PostMapping("save")
    public ResponseEntity<?> save(@Valid @RequestBody AccountRegister request) {
        return ResponseEntity.ok(registerService.save(request));
    }

    @ApiOperation(value = "注册审核打回")
    @ResponseBody
    @GetMapping("repulse")
    @UserAuthenticate(actionCode = "REGISTER_REPULSE")
    public ResponseEntity<?> repulse(@ApiParam(name = "id", value = "注册主键") @RequestParam Long id,
                                     @ApiParam(name = "reason", value = "原因") String reason) {
        return ResponseEntity.ok(registerService.repulse(id,reason));
    }

    @ApiOperation(value = "注册审核通过")
    @ResponseBody
    @GetMapping("adopt")
    @UserAuthenticate(actionCode = "REGISTER_ADOPT")
    public ResponseEntity<?> adopt(@ApiParam(name = "id", value = "注册主键") @RequestParam Long id) {
        return ResponseEntity.ok(registerService.adopt(id));
    }
}